<?php
/**
 * Created by PhpStorm.
 * User: xiaotao
 * Date: 18-5-14
 * Time: 下午4:41
 */

namespace app\manage\controller;
use app\common\model\User;
use think\Request;


class Profile extends Base
{
    protected $mustAuth = false;
    /**
     * 获取用户的基本信息
     * @return \think\response\Json
     */
    public function index () {
        $field = ['username', 'u.name', 'avatar', 'phone', 'email', 'c.name' => 'company', 'g.name' => 'group', 'p.name' => 'post'];
        $user = User::field($field)->alias('u')
            ->leftJoin('group g', 'u.group_id = g.id')
            ->leftJoin('company c', 'u.company_id = c.id')
            ->leftJoin('post p', 'p.id in (u.post_id)')
            ->find($this->baseInfo['uid']);

        $user->company  = $user->company ?: '系统管理员';
        $user->group    = $user->group ?: '超级管理员';
        $user->post     = $user->post ?: '管理员';
        // 需要测试该方法
        return $this->result_json(null, 1, $user);
    }

    /**
     * 更换头像
     * @return \think\response\Json
     */
    public function avatar() {
        // 上传头像，并考虑是否对文件做其他相关处理（缩略图等）
        return $this->result_json('success', 0, ['url' => '123']);
    }

    /**
     * 修改个人信息
     * @param Request $request
     * @return \think\response\Json
     */
    public function update(Request $request) {
        return $this->result_json('update success', 0, null);
    }

    /**
     * 修改单个信息
     * @param Request $request
     * @return \think\response\Json
     */
    public function modify(Request $request) {
        return $this->result_json('modify success', 0, null);
    }

    /**
     * 修改密码
     * @return \think\response\Json
     */
    public function changePassword() {
        return $this->result_json('change success', 0, null);
    }
}